#!/usr/bin/env groovy
package com.timefrom

class JobList {
  def maptry(deploylist,jobmap) {
    def update_job_list = []
    for(int i =0 ;i < deploylist.size(); i++) {
      def job_name = jobmap.get(deploylist[i])
      update_job_list.add(job_name)
    }
    return update_job_list
  }

  def updateJobList(deploylist,jobmap) {
    // 'release_dev:v1,release_test:v2'
    def job_list = jobmap.split(',')
    def update_job_list = []
    def update_map = [:]
    for(String line : job_list) {
      def jobs = line.split(':')
      update_map[jobs[0]] = jobs[1]
    }
    for(int i =0 ;i < deploylist.size(); i++) {
      def job_name = update_map.get(deploylist[i])
      update_job_list.add(job_name)
    }
    return update_job_list.join(',')
  }

  static void main(String[] args) {
//    def deploy_list = ['release_dev','release_test']
//    def deploy_job_list = ["release_dev": "v1","release_test": "v2"]
//    def m = new JobList()
//    def c = m.maptry(deploy_list,deploy_job_list)
//    println(c)
//    println(c.class)
    def deploy_list = ['release_dev','release_test']
    def a = 'release_dev:v1,release_test:v2'
    def m = new JobList()
    def c = m.updateJobList(deploy_list,a)
    println(c)

  }
}
